package com.bbkb.common.vo;


import lombok.Data;

import java.util.Collections;
import java.util.List;

@Data
public class ResultVo<T> {

    private boolean success = false;

    private String code;

    private String msg;

    /**
     * 总条数
     */
    private long total = 0;

    /**
     * 返回的数据
     */
    private List<T> rows = Collections.emptyList();

    public ResultVo() {
        this.code = "999";
        this.msg = "系统异常";
        this.success = false;
    }

    public ResultVo(String code, String msg) {
        this.code = code;
        this.msg = msg;
        this.success = false;
    }

    public ResultVo(long total, List<T> data) {
        this.code = "00";
        this.msg = "结果正常";
        this.success = true;
        this.total = total;
        this.rows = data;
    }

    public static ResultVo success(int total, List data) {
        return new ResultVo(total, data);
    }

    public static ResultVo error() {
        return new ResultVo();
    }

    public static ResultVo error(String msg) {
        ResultVo result = new ResultVo();
        result.setMsg(msg);
        return result;
    }

    public static ResultVo error(String code, String msg) {
        return new ResultVo(code, msg);
    }
}
